package com.shsmi.dsn.controller;

import com.shsmi.dsn.common.Result;
import com.shsmi.dsn.domain.SystemUser;
import com.shsmi.dsn.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/")
public class AuthController {

    @Autowired
    private AuthService authService;

//    @PostMapping(path = "/auth")
//    public Result auth(@RequestParam("loginName") String loginName,
//                       @RequestParam("password") String password){
////        JSONObject jsonObject = JSONUtil.parseObj(request);
////        String loginName = jsonObject.get("loginName").toString();
////        String password = jsonObject.get("password").toString();
//        SystemUser systemUser= authService.verify(loginName,password);
//        if(systemUser == null){
//            return Result.genFailResult();
//        }else{
//            return Result.genSuccessResult(systemUser);
//        }
//    }

    @PostMapping(path = "/auth")
    public Result auth(String loginName,String password){
//        JSONObject jsonObject = JSONUtil.parseObj(request);
//        String loginName = jsonObject.get("loginName").toString();
//        String password = jsonObject.get("password").toString();
        SystemUser systemUser= authService.verify(loginName,password);
        if(systemUser == null){
            return Result.genFailResult();
        }else{
            return Result.genSuccessResult(systemUser);
        }
    }


}
